package com.danskin.wechat.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.danskin.wechat.dao.CustOrderEvaluateDao;
import com.danskin.wechat.dao.CustOrderRecordDao;
import com.danskin.wechat.entity.CustOrderEvaluate;
import com.danskin.wechat.entity.CustOrderRecord;
import com.danskin.wechat.entity.example.CustOrderEvaluateExample;
import com.danskin.wechat.entity.example.CustOrderEvaluateExample.Criteria;
import com.danskin.wechat.entity.example.CustOrderRecordExample;
import com.danskin.wechat.service.CustOrderEvaluateService;
import com.danskin.wechat.util.DateUtils;
import com.danskin.wechat.util.Page;
@Service
public class CustOrderEvaluateServiceImpl implements CustOrderEvaluateService {
	
	@Autowired
	private  CustOrderEvaluateDao custOrderEvaluateDao;
	
	@Autowired
	private CustOrderRecordDao custOrderRecordDao;

	@Override
	public int saveCustOrderEvaluateSelective(CustOrderEvaluate custOrderEvaluate) {
		
		int i = custOrderEvaluateDao.insertSelective(custOrderEvaluate);
		
		CustOrderRecordExample example =new CustOrderRecordExample();
		com.danskin.wechat.entity.example.CustOrderRecordExample.Criteria criteria = example.createCriteria();
		criteria.andOrderNoEqualTo(custOrderEvaluate.getOrderNo());
		CustOrderRecord record=new CustOrderRecord();
		record.setOrderNo(custOrderEvaluate.getOrderNo());
		record.setEvaluateStatus(Byte.valueOf("1"));
		custOrderRecordDao.updateByExampleSelective(record, example);
		return i;
	}

	@Override
	public List<Map<String,Object>> listPageGetCustOrderEvaluate(Page page) {
		List<Map<String,Object>> list = custOrderEvaluateDao.listPageGetCustOrderEvaluate(page);
		return list;
	}

	@Override
	public CustOrderEvaluate selectByPrimaryKey(Integer id) {
		CustOrderEvaluate primaryKey = custOrderEvaluateDao.selectByPrimaryKey(id);
		return primaryKey;
	}

	@Override
	public int updateByPrimaryKeySelective(CustOrderEvaluate custOrderEvaluate) {
		int i = custOrderEvaluateDao.updateByPrimaryKeySelective(custOrderEvaluate);
		return i;
	}

	@Override
	public List<CustOrderEvaluate> selectByOrderAndCust(CustOrderEvaluate custOrderEvaluate) {
		CustOrderEvaluateExample example=new CustOrderEvaluateExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andOrderNoEqualTo(custOrderEvaluate.getOrderNo());
		//createCriteria.andCustExIdEqualTo(custOrderEvaluate.getCustExId());
		List<CustOrderEvaluate> selectByExample = custOrderEvaluateDao.selectByExample(example);
		return selectByExample;
	}

	@Override
	public List<CustOrderEvaluate> exportOrderEvaluate(String name, String mobile, String orderNo, String startTime,
			String endTime, String mpId) {
		// TODO Auto-generated method stub
		if (StringUtils.isNotEmpty(startTime)) {
			startTime = startTime + " " + "00:00:01";
		}
		if (StringUtils.isNotEmpty(endTime)) {
			endTime = endTime + " " + "23:59:59";
		}
		return custOrderEvaluateDao.exportOrderEvaluate(name,mobile,orderNo,startTime,endTime,mpId);
	}

}
